package com.zut.edu.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import com.qmuiteam.qmui.util.QMUIResHelper;
import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView;
import com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView;
import com.zut.edu.R;
import com.zut.edu.bean.Data;

import java.util.List;

public class ListViewAdapter extends BaseAdapter {
    private Context context;
    private List<Data> data;

    public ListViewAdapter(Context context, List<Data> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = new ViewHolder();
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.listview_item,parent,false);
            viewHolder.listItemView = convertView.findViewById(R.id.List_Item);
            convertView.setTag(viewHolder);
        }
        else viewHolder = (ViewHolder) convertView.getTag();


        int height = QMUIResHelper.getAttrDimen(context, com.qmuiteam.qmui.R.attr.qmui_list_item_height);
        createItemView(
                ContextCompat.getDrawable(context,R.mipmap.about_logo),
                data.get(position).getName(),
                data.get(position).getTime(),
                QMUICommonListItemView.VERTICAL,
                QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON,
                height,viewHolder.listItemView);



        return convertView;
    }
    class ViewHolder{
        public QMUICommonListItemView listItemView;
    }

    public void createItemView(@Nullable Drawable imageDrawable, CharSequence titleText, String detailText, int orientation, int accessoryType, int height,QMUICommonListItemView itemView) {
        itemView.setOrientation(orientation);
        itemView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height));
        itemView.setImageDrawable(imageDrawable);
        itemView.setText(titleText);
        itemView.setDetailText(detailText);
        itemView.setAccessoryType(accessoryType);
        itemView.setTipPosition(QMUICommonListItemView.TIP_POSITION_RIGHT);
        itemView.showNewTip(true);

        QMUICommonListItemView.LayoutParamConfig lp = new QMUICommonListItemView.LayoutParamConfig() {
            @Override
            public ConstraintLayout.LayoutParams onConfig(ConstraintLayout.LayoutParams lp) {
                int size = QMUIDisplayHelper.dp2px(context, 30);
                lp.height = size;
                lp.width = size;
                return lp;
            }
        };
        itemView.updateImageViewLp(lp);

    }

}
